<?php
class OrderAdministration
{
    const CACHE_ALL_TABLES_KEY = "tables_all";
    const CACHE_TABLE_ID_PREFIX = "table_";
    const CACHE_SEAT_ID_PREFIX = "seat_";
    const CACHE_USER_ID_PREFIX = "user_";


    public function __construct(){
    }

   private function GetUserId(){
        return $_SESSION["user"]["id"];
    }

   public function PayOrder($id)
   {
       $order = new m_order();
       $orders = $order ->select("",array("id"=>$id));
       $order -> paid = 1;
       $order ->update();

       return $orders;
   }

    public function FreeOrder($id)
    {
        $reservation = new InteractiveReservation();


        $seats = new m_seat();
        $seatsForOrder = $seats -> select("",array("order_id"=>$id));
        foreach ($seatsForOrder as $ps)
        {
            $reservation->TryUnreserveSeat($ps->id);
            $ps-> delete();
        }


    }


   public function GetPaidSeat()
   {
       $orderview = new  m_search_order_result();
       $paidSeats = $orderview -> select("",array("paid"=>1));

       $res = "";

       if (isset($paidSeats))
       {
           foreach ($paidSeats as $ps)
           {
               if ($res == "")
               {
                    $res = $ps -> seats;
               }
                else
                {
                    $res = $res.";".$ps -> seats;
                }
           }
       }

       if($res !="")
       {
           return explode(';',$res);
       }
       else
       {
           return array();
       }


   }
}